package cn.wolfcode.luowowo.website.controller;

import cn.wolfcode.luowowo.acticle.domain.Travel;
import cn.wolfcode.luowowo.acticle.query.TravelQueryObject;
import cn.wolfcode.luowowo.acticle.service.IStrategyCommendService;
import cn.wolfcode.luowowo.acticle.service.ITravelCommendService;
import cn.wolfcode.luowowo.acticle.service.ITravelService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;


/**
 * 主页资源控制器
 */
@Controller
public class IndexController {
    @Reference
    private IStrategyCommendService strategyCommendService;
    @Reference
    private ITravelCommendService travelCommendService;
    @Reference
    private ITravelService travelService;

    /**
     * 跳转到主页接口
     * @return
     */
    @RequestMapping("")
    public String index(Model model){
        //tcs 前5条游记推荐
        model.addAttribute("tcs", travelCommendService.getCommentTop5());
        //scs 推荐1条攻略推荐
        model.addAttribute("scs", strategyCommendService.getCommentTop5().subList(0, 3));

        return "index/index";
    }

    @RequestMapping("/index/travelPage")
    public String travelPage(Model model, @ModelAttribute("qo")TravelQueryObject qo){  //currentPage: 1  orderType: 2
        //按照最新游记， 最热游记2个维度进行游记查询。
        //1最新游记：createTime 倒序排1
        //2最热游记：通过viewnum 倒序排2
        qo.setState(Travel.STATE_RELEASE);
        qo.setPageSize(10);
        model.addAttribute("pageInfo", travelService.query(qo));
        return "index/travelPageTpl";
    }

}
